import { App, Directive } from "vue";
import vueTouch from "./common/touch";
import setupThrottleDirective from './throttle/throttle';
import loadingDirective from '@/components/loading/loading.js'

// 定义一个通用的指令创建函数
function createTouchDirective(eventName) {
  return {
    mounted(el, binding) {
      new vueTouch(el, binding.value, eventName);
    },
    unmounted(el) {
      // 如果vueTouch提供了销毁或解除绑定的方法，应在这里调用
      // 例如: vueTouch.destroy(el);
    },
  };
}

export default (app: App) => {
  // 导入并设置节流指令
  setupThrottleDirective(app);
  // 为不同的触摸事件注册指令
  app.directive("zswipe", createTouchDirective("swipe"));
  app.directive("zswipeleft", createTouchDirective("swipeleft"));
  app.directive("zswiperight", createTouchDirective("swiperight"));
  app.directive("zswipedown", createTouchDirective("swipedown"));
  app.directive("zswipeup", createTouchDirective("swipeup"));
  app.directive("zlongtap", createTouchDirective("longtap"));
  app.directive("loading", loadingDirective);
};
